package com.xr.hr.sys;

import java.util.Random;

import com.xr.common.CommUtil;
import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * getPasswordViewModel
 */
public class getPasswordViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
    // Add your code here
    super.doUpdateData(parameters, outParameters);
  }

  public void Activation(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  
	  Dataset ds =getDataset("datasetForgetPwd");
	  Random r = new Random(System.currentTimeMillis());
		String psw = "";
		OrgIns ois=new OrgIns();
		while (true) {
			psw = ois.getPassword(8, r);
			if (!ois.checkNum(psw) && !ois.checkAlpha(psw)) {
				break;
			}
		}
		outParameters.setValue("psw", psw);
		//CommUtil.executeUpdate("update RT_FORGET_PWD set IS_ACTIVATION=1,ACTIVATION_DATE=sysdate where FORGET_PWD_ID="+ds.getValue("FORGET_PWD_ID"));
		CommUtil.executeUpdate("update rt_user set updtime=sysdate,password=fn_md5('"+psw+"') where user_name = '"+ds.getValue("USER_NAME")+"' and REAL_NAME='"+ds.getValue("REAL_NAME")+"'");
  }

}
